//折半查找
#include <stdio.h>
int BinarySearch(int arr[],int length,int key);
int main(){
	int len;
	int i=0;
	printf("please enter the array length:");
	scanf("%d",&len);
	int add[len]={};
	printf("\nplease enter a ordered array:\n");
	for(i=0;i<len;i++){
		scanf("%d",&add[i]);
//		if(i<len&&add[i+1]<add[i])
//			{
//				printf("\nplease enter a number great than previous one:\n");
//				--i; 
//			}
		}
	int skey=0;
	printf("\nplease enter a number for searching:\n");
	scanf("%d",&skey);
	int index=BinarySearch(add,len,skey);
	if(index==-1)
		printf("No Find!");
	else
		printf("the index of the searched value is %d",index);
	return 0;
	}
int BinarySearch(int arr[],int size,int key)
{
	int min=0;
	int max=size-1;
	while(min<=max){
		int mid=(min+max)/2;
		if(arr[mid]>key)
			max=mid-1;
		else if(arr[mid]<key)
			min=mid+1;
		else
			return mid;
	}
	return -1;
}